<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="line" style="width: 600px;height:400px;float:left"></div>
<script src="/javascripts/echarts-all-3.js"></script>
<script type="text/javascript">
// 基于准备好的dom，初始化echarts实例
var myChart2 = echarts.init(document.getElementById('line'));
var obj = JSON.parse(sessionStorage.getItem("data"));
var keys = Object.keys(obj);
var values = keys.map(function(i){
        return obj[i];
    })

// 指定图表的配置项和数据
var option2 = {
    title: {
        text: 'Nginx访问状态',
        subtext: '请求状态个数'
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        }
    },
    legend: {
        // data: ['个数', '200']
        data:['个数']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type: 'value',
        boundaryGap: [0, 0.01]
    },
    yAxis: {
        type: 'category',
        // data: ['巴西','印尼','美国','印度','中国','世界人口(万)']
        data: keys
    },
    series: [
        {
            name: '个数',
            type: 'bar',
            // data: [10, 15, 20, 30, 35, 40]
            data: values
        },
        // {
        //     name: '200',
        //     type: 'bar',
        //     data: [19325, 23438, 31000, 121594, 134141, 681807]
        // }
    ]
};

setInterval(function(){
    console.log(sessionStorage.getItem("data"))
    obj = JSON.parse(sessionStorage.getItem("data"));
    keys = Object.keys(obj);
    values = keys.map(function(i){
        return obj[i];
    })// 指定图表的配置项和数据
    option2 = {
        title: {
           text: '日志访问来源',
           subtext: '请求个数'
        },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        }
    },
    legend: {
        // data: ['个数', '200']
        data:['个数']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type: 'value',
        boundaryGap: [0, 0.01]
    },
    yAxis: {
        type: 'category',
        // data: ['巴西','印尼','美国','印度','中国','世界人口(万)']
        data: keys
    },
    series: [
        {
            name: '个数',
            type: 'bar',
            // data: [10, 15, 20, 30, 35, 40]
            data: values
        },
        // {
        //     name: '200',
        //     type: 'bar',
        //     data: [19325, 23438, 31000, 121594, 134141, 681807]
        // }
    ]
};
    // console.log(option)
     myChart2.setOption(option2);
},1000)

</script>